from django.http import JsonResponse
from django.views import View
from apps.visual.models import Achievement, TeaCelebration


# 获取茶叶的echarts数据
class TeaAchievement(View):
    def get(self, request):
        tea_achievements = []
        # 获取关于茶叶的echarts所有数据
        try:
            tea_achievement = Achievement.objects.all()
            print(tea_achievement)
        except Exception as error:
            print(error)
            return JsonResponse({"code": 400, "errmsg": "获取关于茶叶的echarts所有数据失败"})
        for tea in tea_achievement:
            tea_achievements.append(
                {"id": tea.id, "tea_output": tea.tea_output, "tea_FigureRation": tea.tea_FigureRation,
                 "tea_SalesVolume": tea.tea_SalesVolume, "tea_ExportAmount": tea.tea_ExportAmount})
        print(tea_achievements)
        return JsonResponse({"code": 200, "errmsg": "OK", "tea_achievement": tea_achievements})


# 获取茶庆数据
class TeaCelebrations(View):
    def get(self, request, name):
        tea_celebrations = []
        try:
            tea_celebration = TeaCelebration.objects.filter(name=name)
            print(tea_celebration)
        except Exception as error:
            print(error)
            return JsonResponse({"code": 400, "errmsg": "获取茶庆数据数据失败"})
        for tea in tea_celebration:
            tea_celebrations.append({"id": tea.id, "name": tea.name, "Festival_Name": tea.Festival_Name,
                                     "Festival_text": tea.Festival_text, "Activity_Name": tea.Activity_Name,
                                     "Activity_text": tea.Activity_text, "Activity_time": tea.Activity_time})
        print(tea_celebrations)
        return JsonResponse({"code": 200, "errmsg": "OK", "tea_celebration": tea_celebrations})
# 北　京
